package com.make.sunflower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.make.sunflower.dao.UserMapper;
import com.make.sunflower.entity.User;
import com.make.sunflower.service.UserIService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenjiaxin
 * @since 2022-02-27
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> implements UserIService {

    @Transactional(rollbackFor = Exception.class)
    public boolean register(User user){
        User userByAccount = getOne(new QueryWrapper<User>().lambda()
                .select(User::getId).eq(User::getAccount, user.getAccount()));
        return userByAccount == null && save(user);
    }
}
